<ui:composition xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	template="/layout/layout_nav_footer_adm.xhtml">
	<ui:define name="titre">
		<p:graphicImage value="/img/administration.png" />
	</ui:define>
	<ui:define name="content">
		
			<fieldset id="fieldset">
			    <legend id="fieldset2">User management</legend>
			    
			    
			    <h:form styleClass="form-horizontal" rendered="#{loginbean.adminLogged == true}" id="all_user">
			    <div class="span5 well" >
				    <p:dataTable style="text-align:center" var="user" value="#{usermanagerbean.userList}" rowStyleClass="#{usermanagerbean.currentUser.id == user.id ? 'rowSelected' : null}"
				    			 paginator="true" rows="7" paginatorTemplate="{PreviousPageLink} {PageLinks} {NextPageLink}">
				    	<p:column headerText="Nom">
				    		<h:outputText value="#{user.lastName}" />
				    	</p:column>
				    	<p:column headerText="Login">
				    		<h:outputText value="#{user.login}" />
				    	</p:column>
				    	<p:column headerText="Admin">
				    		<h:outputText rendered="#{user.isAdmin == true}" class="ui-icon ui-icon-check" style="margin:auto"/>
				    	</p:column>
				    	<p:column>
				    		<p:commandButton id="select_button" icon="ui-icon-search" title="View" update=":current_user :all_user">
				    			<f:setPropertyActionListener value="#{user}" target="#{usermanagerbean.currentUser}" />
				    		</p:commandButton>
				    	</p:column>
				    		
				    </p:dataTable>
				    <div style="width:30%; margin:auto;">
				    <h:commandButton style="width:100%; margin-top:5%;" id="add_button" value="ADD" styleClass="btn btn-primary" update=":current_user" >
				    	<f:setPropertyActionListener value="#{null}" target="#{usermanagerbean.currentUser}" />
				    </h:commandButton>
			    	</div>
			    </div>
			    </h:form>
			
			
			
			     <h:form styleClass="form-horizontal" rendered="#{loginbean.adminLogged == true}" id="current_user" autoUpdate="true">
			    <div class="span5 well" id="current_user">
			    		<div class="control-group">
					    	<h:outputLabel styleClass="control-label" for="firstname" value="Prénom :" />
					    	<div class="controls">
					      		<h:inputText id="firstname" value="#{usermanagerbean.currentUser.firstName}" requiredMessage="Votre prénom doit être renseigné" required="true">
					      			<f:validator validatorId="UserNameValidator" />
					      			<f:ajax event="blur" render="messageFirstName" />
					      		</h:inputText>
					      		<p:message id="messageFirstName" for="firstname" style="color:red" />
						    </div>
				  		</div>
				    	<div class="control-group">
					    	<h:outputLabel styleClass="control-label" for="lastname" value="Nom :" />
					    	<div class="controls">
					      		<h:inputText id="lastname" value="#{usermanagerbean.currentUser.lastName}" requiredMessage="Votre nom doit être renseigné" required="true">
					      			<f:validator validatorId="UserNameValidator" />
					      			<f:ajax event="blur" render="messageLastname" />
					      		</h:inputText>
					      		<p:message id="messageLastname" for="lastname" style="color:red" />
						    </div>
				  		</div>
				  		<div class="control-group">
					    	<h:outputLabel styleClass="control-label" for="age" value="Age :" />
					    	<div class="controls">
					      		<p:inputMask mask="99" id="age" value="#{usermanagerbean.currentUser.age}" requiredMessage="Votre âge doit être renseigné" required="true" >
					      			<f:validator validatorId="UserAgeValidator" />
					      			<f:ajax event="blur" render="messageAge" />
					      		</p:inputMask>
					      		<p:message id="messageAge" for="age" style="color:red" />
						    </div>
				  		</div>
				  		<div class="control-group">
					    	<h:outputLabel styleClass="control-label" for="mail" value="E-mail :" />
					    	<div class="controls">
					      		<h:inputText id="mail" value="#{usermanagerbean.currentUser.email}" requiredMessage="Votre email doit être renseigné" required="true">
					      			<f:validator validatorId="UserEmailValidator" />
					      			<f:ajax event="blur" render="messageEmail" />
					      		</h:inputText>
					      		<p:message id="messageEmail" for="mail" style="color:red" />
						    </div>
				  		</div>
				  		<div class="control-group">
					    	<h:outputLabel styleClass="control-label" for="login"  value="Login :" />
					    	<div class="controls">
					      		<h:inputText id="login" value="#{usermanagerbean.currentUser.login}" requiredMessage="Votre login doit être renseigné" required="true">
					      			<f:validator validatorId="UserLoginValidator" />
					      			<f:ajax event="blur" render="messageLogin" />
					      		</h:inputText>
					      		<p:message id="messageLogin" for="login" style="color:red" />
						    </div>
				  		</div>
				  		<div class="control-group">
					    	<h:outputLabel styleClass="control-label" for="password" value="Mot de passe :" />
					    	<div class="controls">
					      		<p:password id="password" value="#{usermanagerbean.currentUser.password}" required="true" requiredMessage="Votre mot de passe doit être renseigné" match="password2" redisplay="true" >
					      			<f:validator validatorId="UserPasswordValidator" />
					      			<f:ajax event="blur" render="messagePassword2" />
					      		</p:password>
					      		<p:message id="messagePassword" for="password" style="color:red" />
						    </div>
				  		</div>
				  		<div class="control-group">
					    	<h:outputLabel styleClass="control-label" for="password2" value="Mot de passe* :" />
					    	<div class="controls">
					      		<p:password id="password2" value="#{usermanagerbean.currentUser.password}" requiredMessage="Votre mot de passe doit être confirmé" required="true"  redisplay="true" >
					      			<f:ajax event="blur" render="messagePassword2" />
					      			<f:validator validatorId="UserPasswordValidator" />
					      		</p:password>
					      		<p:message id="messagePassword2" for="password2" style="color:red" />
					      	</div>
						    
				  		</div>
				  		<div class="control-group">
					    	<h:outputLabel styleClass="control-label" for="admin" value="Admin :" />
					    	<div class="controls">
					      		<p:selectBooleanCheckbox id="admin" value="#{usermanagerbean.currentUser.admin}" />
					      	</div>
						    
				  		</div>
				  		<div class="control-group">
		    				<div class="controls">
		    					<h:commandButton style="margin-right:10%;" id="buttonUpdate" value="Save" type="submit" styleClass="btn btn-primary" update=":all_user" action="#{usermanagerbean.saveUser}" actionListener="#{usermanagerbean.attrListener}" />
		    					<h:commandButton id="buttonDelete" value="Delete" type="submit" styleClass="btn btn-primary" update=":current_user :all_user" action="#{usermanagerbean.delete}" actionListener="#{usermanagerbean.attrListener}"/>
		    					<p:message id="messageButtonDelete" for="buttonDelete" errorStyle="color:red" infoStyle="color:green" style="margin-top:10px" />
		    					<p:message id="messageButtonUpdate" for="buttonUpdate" errorStyle="color:red" infoStyle="color:green" style="margin-top:10px" />
		    				</div>
		    			</div>
			   	</div>
			   	</h:form>
			</fieldset>
		
	</ui:define>
</ui:composition>